package org.jumiz.javafx.client.util;

import com.alibaba.fastjson2.JSON;
import lombok.Data;

/**
 * 访问接口或者数据，切换本地和远程访问数据。
 */
public class ApiUtil {

    @Data
    public static class Response {
        private String code;
        private String mesg;
        private Object data;

        public Response() {
            this(null);
        }

        public Response(String code) {
            this(code, null);
        }

        public Response(String code, String mesg) {
            this(code, mesg, null);
        }

        public Response(String code, String mesg, Object data) {
            this.code = code;
            this.mesg = mesg;
            this.data = data;
        }

        public boolean isSuccess() {
            return "1".equals(code);
        }

        @Override
        public String toString() {
            return JSON.toJSONString(this);
        }
    }

    public static Response request(Object data) {
        return new Response();
    }
}
